package com.weipai.springboot.module.mapper;

import com.weipai.springboot.model.Goods;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Update;

import java.util.List;
import java.util.Map;

/**
 * 商品
 */
public interface GoodsMapper {
    int deleteByPrimaryKey(String goodsId);

    int insert(Goods record);

    int insertSelective(Goods record);

    Goods selectByPrimaryKey(String goodsId);

    Goods selectByPrimaryKey22(String goodsId);

    int updateByPrimaryKeySelective(Goods record);


    int updateByPrimaryKey(Goods record);

    //删除商品
    @Update("update c_goods set goods_del=-1 where goods_id=#{id}")
    int deleteByGoodsById(String id);

    //更改商品的状态
    //@Update("update c_goods set goods_status=#{goodsStatus}, update_time=date_format(now(), '%Y-%m-%d %H:%i:%s') " +
    //        "where goods_id=#{goodsId}")
    int changeGoodsStatus(@Param("goodsId") String goodsId, @Param("goodsStatus") Integer goodsStatus);

    //通过货品编号查出所有的商品
    List<Goods> selectGoodsBySpuNumber(String spuNumber);


    List<Goods> selectGoodsBySpuNumber22(String spuNumber);

    List<Map<String, Object>> searchGoodsByCategoryId(@Param("categoryId") String categoryId, @Param("start") int start, @Param("size") int size);

    int countGoodsByCategoryId(@Param("categoryId") String categoryId);

    List<Map<String, Object>> searchBoutiqueGoods(@Param("shopId") String shopId, @Param("categoryId") String categoryId, @Param("size") Integer size);

    List<Map<String, Object>> searchPopularBountiqueGoods(@Param("shopId") String shopId, @Param("size") Integer size);

    List<Map<String, Object>> searchPopularGoodsByShop(@Param("shopId") String shopId, @Param("start") Integer start, @Param("size") Integer size);

    List<Map<String, Object>> searchBigBrandBountiqueGoods(@Param("size") Integer size);

    String getProductCategoryId(String goodsId);

    List<Map<String, Object>> searchRelatedGoods(@Param("categoryId") String categoryId, @Param("size") Integer size);

    List<Map<String, Object>> searchRecommendGoods(@Param("categoryId") String categoryId, @Param("size") Integer size);

    List<Map<String, Object>> searchSpecialGoods(@Param("start") Integer start, @Param("size") Integer size);

    Integer countSpecialGoods();

    List<Map<String, Object>> searchNewGoods(@Param("size") Integer size);

    //通过shopid  搜索 商品数量
    int countByShop(@Param("shopId") String shopId);

    //通过商品编号查询商品的基础信息
    List<Map<String,Object>> getGoodsInfoBySkuNumber(String spuNumber);

    //查询此店铺下面一共有多少货品
    Integer getGoodsAmountByShopId(String shopId);

    //查询产品图片、商品名称、商品规格
    Map<String,Object> getGoodsInfoByGoodsId(String goodsId);
    

    //分页查询单一货品的所有商品
    List<Map<String,Object>> selectAllGoodsByProductId(@Param("start") Integer start, 
                                                       @Param("size") Integer size, 
                                                       @Param("spuNumber") String spuNumber);

    //分页查询单一货品的所有商品
    Integer selectAllGoodsByProductIdAmount(String spuNumber);

    //通过product的id查询商品的id
    List<Map<String,Object>> getGoodsIdByProductId(String spuNumber);
    
    //检索商品
    List<Map<String,Object>> searchGoods(@Param("start") Integer start, @Param("size") Integer size, @Param("search") String search);

    //检索商品的数量
    Integer searchGoodsAmount(@Param("search") String search);

    //商品报表信息
    List<Map<String,Object>> goodsStatement(@Param("start") int start, @Param("end") Integer end);

    //商品数量
    int getGoodsAmount();

    //得到商品的skuNumber
    Map<String,Object> getSkuNumberByGoodsId(String goodsId);

    //更改商品的销售数量
    @Update("update c_goods set sold_out_goods = sold_out_goods + #{goodsNumber} where sku_number=#{sku}")
    int updateGoodsSoldOutNumber(@Param("sku") String sku, @Param("goodsNumber") Integer goodsNumber);

    Map<String,Object> getMaxSkuNumberFlag(String spuNumber);

    Map<String,Object> getMaxSkuNumber();

    //通过商品id查询出评价商品赠送的积分
    Map<String,Object> getCommentIntegralByGoodsId(String goodsId);


    //app前端获取商品价格
    List<Map<String,Object>> getGoodsInfoAndPriceBySpuNumber(@Param("spuNumber") String spuNumber, @Param("memberLevelId") String memberLevelId);

    // 对外接口  返还商品的信息
    List<Map<String,Object>> getGoodsMessage();

    //通过商品编码查询商品
    List<Map<String,Object>> getGoodsInfoAndPriceBySkuNumber(@Param("skuNumber") String skuNumber, 
                                                             @Param("memberLevelId") String memberLevelId);
}